04 / 06

What is the difference between `==` and `===` operators?

  1. 1

    == is the equality operator that performs type coercion, meaning it converts the operands to the same type before making the comparison.

  2. 2

    === is the strict equality operator that compares both value and type without performing type

In 99% of cases, you should always use ===. Using == can lead to strange, silent bugs that are hard to track down because JavaScript is making assumptions behind your back.
The Only Common Exception: Some developers use == specifically to check if a value is Nullish (either null or undefined) in one go
Difficulty: 2/10
Topics: type coercion, strict vs loose equality, implicit conversion

Scenario Questions

0-2 years experience
  1. 1

    You need to check if a variable userId equals the string '123'. Which operator would you use and why?

  2. 2

    If you write if (value == null) { ... }, what values will cause the block to run? Explain the behavior.

  3. 3

    Given let a = '0'; let b = 0;, what will a == b and a === b evaluate to? Explain.

2-5 years experience
  1. 1

    While debugging a feature, you notice that a condition using == is unexpectedly true for an object. Walk me through how you would investigate and fix it.

  2. 2

    Your team wants to enforce consistent equality checks across the codebase. What trade‑offs would you consider when introducing a lint rule to ban ==?

  3. 3

    A JSON API returns numbers as strings, and a comparison using === fails. How would you handle this without introducing bugs elsewhere?

5-8 years experience
  1. 1

    You are refactoring a large legacy module that heavily uses ==. Describe a systematic approach to migrate to === while minimizing regression risk.

  2. 2

    In a performance‑critical loop, you need to compare primitive values. Discuss any measurable impact of using === vs == and how you would benchmark it.

  3. 3

    Your microservice communicates with a loosely typed client that sometimes sends booleans as 'true' strings. How would you design a validation layer that correctly handles equality without relying on coercion?

8+ years experience
  1. 1

    Your organization is planning a migration from a mixed JavaScript/TypeScript codebase to strict TypeScript. How would you address the widespread use of == in terms of tooling, code reviews, and long‑term maintainability?

  2. 2

    When defining a shared utility library used across multiple teams, what guidelines would you set regarding equality operators, and how would you enforce them across CI pipelines?

  3. 3

    Consider a large monorepo where some packages target older browsers that lack Object.is. How would you decide between using ===, a polyfilled Object.is, or a custom equality helper for consistency?

Follow-up Questions

  • Can you show a real bug that arose from using `==`?
  • How would you enforce the use of `===` in a codebase?
  • Are there any performance differences between the two operators?